package com.smart_campus.bus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.bus.vo.BuildingVo;
import com.smart_campus.sys.common.DataGridView;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.bus.mapper.BuildingMapper;
import com.smart_campus.bus.domain.Building;
import com.smart_campus.bus.service.BuildingService;

import java.util.List;

/**
 * @author Alfred
 * @time: 2020/6/20 10:31
 * 
 */
@Service
public class BuildingServiceImpl implements BuildingService{

    @Resource
    private BuildingMapper buildingMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
    @CacheEvict(cacheNames = "com.smart_campus.bus.service.impl.BuildingServiceImpl",key = "#id")
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return buildingMapper.deleteByPrimaryKey(id);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.bus.service.impl.BuildingServiceImpl",key = "#result.id")
    @Override
    public Building insert(Building record) {
        buildingMapper.insert(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.bus.service.impl.BuildingServiceImpl",key = "#result.id")
    @Override
    public Building insertSelective(Building record) {
        buildingMapper.insertSelective(record);
        return record;
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
    @CachePut(cacheNames = "com.smart_campus.bus.service.impl.BuildingServiceImpl",key = "#result.id")
    @Override
    public Building selectByPrimaryKey(Integer id) {
        return buildingMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Building record) {
        return buildingMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Building record) {
        return buildingMapper.updateByPrimaryKey(record);
    }

    @Override
    public DataGridView queryBuilding(BuildingVo buildingVo) {
        Page<Object> page = PageHelper.startPage(buildingVo.getPage(),buildingVo.getLimit());
        List<Building> buildings = this.buildingMapper.queryBuilding(buildingVo);
        return new DataGridView(page.getTotal(),buildings);
    }

    @Override
    public List<Building> selall() {
        return this.buildingMapper.selall();
    }

}
